import { getList } from '@/apis/commonCrud'
import dayjs from 'dayjs'

export const knowledgeColumn = [
    {
        label: '标题',
        prop: 'title',
        search: true,
        span: 24,
        rules: [
            {
                required: true,
                message: '此项必填',
                trigger: 'blur',
            },
        ],
    },
    {
        label: 'collection名称',
        prop: 'collectionName',
        labelTip: '向量数据库中collection名称，需要唯一',
        editDisabled: true,
        rules: [
            {
                required: true,
                message: '此项必填',
                trigger: 'blur',
            },
        ],
        span: 24,
    },
    {
        label: '向量化模型',
        prop: 'embedModelId',
        editDisabled: true,
        type: 'table',
        rules: [
            {
                required: true,
                message: '此项必填',
                trigger: 'blur',
            },
        ],
        children: {
            column: [
                {
                    label: '名称',
                    prop: 'name',
                    search: true,
                },
                {
                    label: 'SDK',
                    prop: 'sdk',
                },
                {
                    label: 'baseURL',
                    prop: 'baseURL',
                },
                {
                    label: 'apiKey',
                    prop: 'apiKey',
                    formatter(_form, val) {
                        return val.length > 0 ? '******' : ''
                    },
                },
                {
                    label: 'model',
                    prop: 'model',
                },
            ],
        },
        onLoad: async ({ page, value, data }, callback) => {
            if (value) {
                const res = await getList('bigModelConfigs', {
                    id: value,
                    type: 'embed',
                    page: 1,
                    pageSize: 1,
                })
                if (res.success) {
                    callback({
                        embedModel: res.data.rows[0]
                    })
                    return
                }
            }
            if (!page) return
            const res = await getList('bigModelConfigs', {
                ...data,
                type: 'embed',
                page: page.currentPage,
                pageSize: 10,
            })
            if (res.success) {
                callback({
                    total: res.data.count,
                    data: res.data.rows,
                })
            }
        },
        formatter: (row) => {
            if (row.embedModel && row.embedModel.name) {
                return row.embedModel.name
            }
        },
        props: {
            disabled: 'disabled',
            label: 'name',
            value: 'id',
        },
        span: 24,
    },
    {
        label: '简介',
        prop: 'description',
        type: 'textarea',
        span: 24,
        overHidden: true,
        minWidth: 200,
        // formatter: () => '...',
    },
    {
        label: '发布时间',
        prop: 'publishTime',
        bind: 'publishTime',
        type: 'datetime',
        formatter: (_row, val) => {
            return val ? dayjs(val).format('YYYY-MM-DD HH:mm:ss') : ''
        },
        span: 9,
        value: dayjs().format('YYYY-MM-DD HH:mm:ss'),
    },
]
